package com.fenxiangtech.mall.manager;

import com.fenxiangtech.mall.dao.OrderProductDAO;
import com.fenxiangtech.mall.model.OrderProduct;
import com.fenxiangtech.mall.model.qc.OrderProductQC;
import com.fenxiangtech.mall.model.qc.Page;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

@Component
public class OrderProductManager {

    @Autowired
    private OrderProductDAO orderProductDAO;

    public List<OrderProduct> queryOrderProduct(OrderProduct orderProduct, Integer pageIndex , Integer pageSize){
        Page page = new Page(pageIndex,pageSize);
        OrderProductQC qc  = new OrderProductQC();
        qc.setPage(page);
        BeanUtils.copyProperties(orderProduct,qc);
        List<OrderProduct> orderProducts = orderProductDAO.listOrderProduct(qc);
        return orderProducts;
    }

    public Long countOrderProduct(OrderProduct orderProduct){
        OrderProductQC qc  = new OrderProductQC();
        BeanUtils.copyProperties(orderProduct,qc);
        Long count = orderProductDAO.countOrderProduct(qc);
        return count;
    }

    public int saveOrderProduct(OrderProduct orderProduct){

        if(orderProduct.getId()!=null){
            return orderProductDAO.updateOrderProduct(orderProduct);
        }else {
            return orderProductDAO.insertOrderProduct(orderProduct);
        }

    }
    public int deleteOrderProduct(Long id){

        return orderProductDAO.deleteOrderProductById(id);

    }



}
